/**
 * Carnegie Mellon University
 * School of Computer Science
 * MSIT eBusiness Technology
 * 
 * Team 8 - Infinity (2011 Spring)
 * infinity-team8@googlegroups.com
 * 
 * Professor: Jeffrey L. Eppinger
 * Program Faculty: Sujata Telang
 */

package model;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.mybeans.dao.DAOException;
import org.mybeans.factory.BeanTable;

public class Model {
	private CustomerDAO customerDAO;
	private EmployeeDAO employeeDAO;
	private FundDAO fundDAO;
	private TransactionDAO transactionDAO;
	private PositionDAO positionDAO;
	private FundPriceHistoryDAO fundPriceHistoryDAO;
	private GlobalDAO globalDAO;
	private SearchDAO searchDAO;

	public Model(ServletConfig config) throws ServletException {
		try {
			String csvDirStr = config.getInitParameter("csvDir");
			if (csvDirStr != null && csvDirStr.length() > 0) {
				File csvDir = new File(csvDirStr);
				BeanTable.useCSVFiles(csvDir);
			} else {
				String jdbcDriver = config.getInitParameter("jdbcDriverName");
				String jdbcURL = config.getInitParameter("jdbcURL");
				BeanTable.useJDBC(jdbcDriver, jdbcURL);
			}

			customerDAO = new CustomerDAO();
			employeeDAO = new EmployeeDAO();
			fundDAO = new FundDAO();
			transactionDAO = new TransactionDAO();
			positionDAO = new PositionDAO();
			fundPriceHistoryDAO = new FundPriceHistoryDAO();
			globalDAO = new GlobalDAO();
            searchDAO =new SearchDAO();
		} catch (DAOException e) {
			throw new ServletException(e);
		}
	}

	public SearchDAO getSearchDAO() {
		return searchDAO;
	}

	public CustomerDAO getCustomerDAO() {
		return customerDAO;
	}

	public EmployeeDAO getEmployeeDAO() {
		return employeeDAO;
	}

	public FundDAO getFundDAO() {
		return fundDAO;
	}

	public TransactionDAO getTransactionDAO() {
		return transactionDAO;
	}

	public PositionDAO getPositionDAO() {
		return positionDAO;
	}

	public FundPriceHistoryDAO getFundPriceHistoryDAO() {
		return fundPriceHistoryDAO;
	}

	public GlobalDAO getGlobalDAO() {
		return globalDAO;
	}
}
